class Admin::SportsController < Admin::BaseController
  def index
    @sports = Sport.paginate :page=>params[:page],:order=>"position asc"
  end

  def update
    @sport = Sport.find params[:id]
    if @sport.update_attributes params[:sport]
      flash[:notice] = 'updated successful'
      redirect_to admin_sports_path
    else
      render :action=>'edit'
    end
  end

  def update_position
    @sports = Sport.find Array(params[:id])
    positions = Array(params[:position])
    @sports.each_with_index do |sport,index|
      sport.position = positions[index]
      sport.save
    end
    flash[:notice] = "updated successful."
    redirect_to admin_sports_path
  end

  def create
    @sport = Sport.new params[:sport]
    if @sport.save
      flash[:notice] = 'success created.'
      redirect_to admin_sports_path
    else
      render :action=>'new'
    end
  end

  def destroy
    @sport = Sport.find params[:id]
    @sport.destroy
    flash[:notice] = 'success deleted.'
    redirect_to admin_sports_path
  end

  def new
    @sport = Sport.new
  end

  def edit
    @sport = Sport.find params[:id]
  end
  
end
